package com.alin.location.set;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.SetData(Setting.dataObj.list.get(position));
    }

    @Override
    public int getItemCount() {
        return Setting.dataObj.list.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public  View itemView;

        public ViewHolder(@NonNull View v) {
            super(v);
            itemView = v;
        }

        public void SetData(Setting.LocationData data){

            TextView lng = itemView.findViewById(R.id.lng);
            lng.setText("经度(lng):" + Long.toString(data.lng));

            TextView addr = itemView.findViewById(R.id.addr);
            addr.setText("地址:" + data.addr);
        }
    }
}